#include "GeneticTraining.h"
#include <cmath>
#include "timer.h"



#ifndef M_PI
#define M_PI           3.14159265358979323846
#endif

int main(int argc, char* argv[])
{

	ofstream ofs;
	ofs.open ("sin_1.dat");
	for(float i = 0.0 ; i <= 90.0 ; i += 1.0)
		ofs<<i<<" "<<sin ((i*M_PI)/180.0)<<endl;
	ofs.close ();

	ofs.open ("sin_1_5.dat");
	for(float i = 0.0 ; i <= 90.0 ; i += 1.5)
		ofs<<i<<" "<<sin ((i*M_PI)/180.0)<<endl;
	ofs.close ();

	ofs.open ("sin_0_25.dat");
	for(float i = 0.0 ; i <= 90.0 ; i += 0.25)
		ofs<<i<<" "<<sin ((i*M_PI)/180.0)<<endl;
	ofs.close ();

	ofs.open ("sin_0_5.dat");
	for(float i = 0.0 ; i <= 90.0 ; i += 0.5)
		ofs<<i<<" "<<sin ((i*M_PI)/180.0)<<endl;
	ofs.close ();

	ofs.open ("sin_2_5.dat");
	for(float i = 0.0 ; i <= 90.0 ; i += 2.5)
		ofs<<i<<" "<<sin ((i*M_PI)/180.0)<<endl;
	ofs.close ();

	
	int *x = new int[3];
	x[0] = 1;
	x[1] =6;
	//x[2] = 3;
	x[2] = 1;




	GeneticTraining *g = new GeneticTraining(3,x);
	g->initializePopulation ();


	
	ofs.open ("performance.dat");
	timer t;
	double totalTime = 0.0;


	while(g->getMinFitness () > DESIRD_ERROR_RATE && g->mGenerationNumber < MAX_GENERATION_NUMBER){
	
		t.start ();	
		g->cycle ();
		t.stop ();
		totalTime += t.elapsed_time ();
		ofs<<"Generation : "<<g->mGenerationNumber<<" elapsed time: "<<t.elapsed_time ()<< "Total time: "<<totalTime<<endl;
		
		
	}

	
	
	ofs.close ();
	g->setANNweightsWithBestChromosome ();

	double* input = new double[1];

	input[0] = 90;
	double *output = g->getANNresult (input);
	cout<<endl<<endl<<"Real value for sin "<<input[0]<<" : "<<sin(input[0]*M_PI /180) << " calculated output : "<<output[0]<<endl;

	input[0] = 0;
	output = g->getANNresult (input);
	cout<<endl<<endl<<"Real value for sin "<<input[0]<<" : "<<sin(input[0]*M_PI /180) << " calculated output : "<<output[0]<<endl;

	input[0] = 75;
	output = g->getANNresult (input);
	cout<<endl<<endl<<"Real value for sin "<<input[0]<<" : "<<sin(input[0]*M_PI /180) << " calculated output : "<<output[0]<<endl;

	input[0] = 11;
	output = g->getANNresult (input);
	cout<<endl<<endl<<"Real value for sin "<<input[0]<<" : "<<sin(input[0]*M_PI /180) << " calculated output : "<<output[0]<<endl;

	input[0] = 24;
	output = g->getANNresult (input);
	cout<<endl<<endl<<"Real value for sin "<<input[0]<<" : "<<sin(input[0]*M_PI /180) << " calculated output : "<<output[0]<<endl;

	g->release ();


	return 0;

}

